package cate.game.play.skill.passive.hero;

import cate.common.table.d.GDCamp;
import cate.common.util.XT;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.skill.FighterCD;
import cate.game.play.skill.passive.PassiveHandler;

import java.util.List;

/**
 * 当生命值低于50%时，净化并恢复自身20%最大生命值，
 * 并为自身附加【海神护体】(此状态下【索命鱼叉】无冷却且附加诅咒的概率提升10%)，
 * 为所有暗系英雄附加【海神咆哮】，
 */
public class 海神惊涛PH extends PassiveHandler {


	private int 血量;

	private List<Integer> 自身buff;

	private int 暗系buff;

	private int 冷却;

	//血量=5000&自身buff=??#??&暗系buff=？？&冷却=99
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		血量 = args.getInt("血量", 0);
		自身buff = args.getIntList("自身buff");
		暗系buff = args.getInt("暗系buff", 0);
		冷却 = args.getInt("冷却", 15);
	}

	@Override
	public void parseExt(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		冷却 += args.getInt("冷却", 0);
	}


	private int lastAddRound;



	public boolean isAddBuff() {
		return lastAddRound>0;
	}

	@Override
	public void onMoveDone(MoveCtx move, TimeActionCtx action) {
		if (FighterCD.inCD(lastAddRound, 冷却, action.getRound().index)) {
			return;
		}
		if (skill.owner.isDead()) {
			return;
		}
		if (skill.owner.attr.total().hpCurRate() > 血量) {
			return;
		}
		lastAddRound = action.getRound().index;
		skill.owner.buff.tryDispelBad(action);
		if(XT.isNotBlank(自身buff)){
			for (Integer buff : 自身buff) {
				skill.owner.buff.tryAddByTid(action, buff);
			}
		}
		if (暗系buff > 0) {
			for (Fighter target : skill.owner.getFightTeam().getFightersAlive()) {
				if (target.getCamp() == GDCamp.Type.C6) {
					target.buff.tryAddByTid(action, skill.owner, 暗系buff);
				}
			}
		}
	}
}
